package main.od;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class CommentPrint {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] inputArr = scanner.nextLine().split(",");
        ArrayList<Node> nodes = new ArrayList<>();
        Map<Integer,String> outputMap = new HashMap<>();
        for (int i = 0;i < inputArr.length;i+=2){
            String comment = inputArr[i];
            int recover = Integer.parseInt(inputArr[i + 1]);
            int row = 1;
            for (int j = nodes.size() - 1;j >=0;j--){
                Node node = nodes.get(j);
                if (node.recover != 0){
                    node.recover--;
                    row = node.row + 1;
                }
            }
            Node node = new Node(row, comment, recover);
            nodes.add(node);
            outputMap.put(row,outputMap.getOrDefault(row,"") + comment + " ");
        }
        for (String output : outputMap.values()){
            System.out.println(output);
        }
    }
    static class Node{
        private int row;
        private String comment;
        private int recover;

        public Node(int row, String comment, int recover) {
            this.row = row;
            this.comment = comment;
            this.recover = recover;
        }
    }
}
